package com.hnhegui.backend.platform.controller.merchant;

import com.hnhegui.backend.entity.PageResult;
import com.hnhegui.backend.entity.Result;
import com.hnhegui.backend.platform.service.merchant.RestProductService;
import com.hnhegui.backend.platform.vo.merchant.common.ProductListItem;
import com.hnhegui.backend.platform.vo.merchant.response.ProductDetailResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品Controller
 */
@RestController
@RequestMapping("/rest/api/products")
public class RestProductController {

    @Autowired
    private RestProductService productService;

    /**
     * 商品列表查询
     */
    @GetMapping
    public Result<PageResult<ProductListItem>> getProductList(
            @RequestParam(required = false) String category,
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false) String sortBy,
            @RequestParam(required = false) String sortOrder,
            @RequestParam(required = false) Integer page,
            @RequestParam(required = false) Integer pageSize) {
        
        PageResult<ProductListItem> result = productService.getProductList(
                category, keyword, sortBy, sortOrder, page, pageSize);
        return Result.success(result);
    }

    /**
     * 商品详情查询
     */
    @GetMapping("/{productId}")
    public Result<ProductDetailResponse> getProductDetail(@PathVariable Long productId) {
        ProductDetailResponse response = productService.getProductDetail(productId);
        return Result.success(response);
    }
}
